package com.angel.sensors.model;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

/**
 * Clase base para los sensores de hardware proporcionados por el servicio de los sensores android
 */
public abstract class HardwareSensorMeter extends PhysicalMeter implements SensorEventListener {
    protected SensorManager sensorManager;
    protected Sensor sensor;
    
    public HardwareSensorMeter(Context context, int sensorType) {
        super(context);
        
        sensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
        sensor = sensorManager.getDefaultSensor(sensorType);
    }

    public boolean isPresent() {
        return sensor != null;
    }
    
    @Override
    protected void onStart() {
        sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    protected void onStop() {
        sensorManager.unregisterListener(this);
    }
    
    
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }

    
    public void onSensorChanged(SensorEvent event) {
    }   
}
